
<div class="panel-heading">
	<div id="data-edit-button">
		<button type="button" class="btn btn-primary" onclick="toggleView()">Bearbeiten</button>
		<button type="button" class="btn btn-danger pull-right" onclick="deleteProduct(<?= HTML::Write($this->Produkt->ID); ?>)">Entfernen</button>
	</div>
</div>

<div class="panel-body">
	<!-- Anzeige der Daten -->
	<div id="data_view">
		<div id="view_produkt_preis" class="pull-right"><?= HTML::Write($this->Produkt->Preis); ?> &euro;</div>
		<h3 id="view_produkt_name" class="panel-title"><?= HTML::Write($this->Produkt->Name); ?></h3>
		<div class="clearfix" />
		<span id="view_produkt_beschreibung"><?= HTML::Write($this->Produkt->Beschreibung); ?></span>
		<br/>
		<br/>
		<div class="panel panel-default">
			<div class="panel-heading">
				<b>Produkt Bilder</b>
			</div>
			<div class="panel-body">
			<?php
				if (count($this->Bilder) > 0)
				{
					foreach($this->Bilder as $bild)
					{
			?>
						<img src="<?= HTML::ProductPicture($bild->ProduktID, $bild->Source); ?>" width="140" height="140" alt="<?= $bild->Beschreibung; ?>" class="img-thumbnail">
			<?php
					}
				}
				else
				{
					echo HTML::Write("keine Bilder für das Produkt vorhanden");
				}
			?>
			</div>
			<div class="panel-footer">
				<button type="button" class="btn btn-primary" onclick="toggleAddPic()"><?= HTML::Write("Neues Bild hinzufügen"); ?></button>
				<form id="add_picture" action="index.php" method="POST" class="form-horizontal" role="form" enctype="multipart/form-data">
					<input type="hidden" name="c" value="Product" />
					<input type="hidden" name="a" value="AddPicture" />
					<input type="hidden" name="p_id" value="<?= HTML::Write($this->Produkt->ID); ?>" />
					
					<!-- Datei -->
					<input type="file" class="btn btn-file" name="p_source" />
					
					<!-- Name -->
					<div class="form-group string required bild-name">
						<label class="col-sm-4 string required control-label" for="edit_bild_name">Name</label>
						<div class="col-sm-6 controls">
							<input class="form-control string required" id="edit_bild_name" name="b_name" type="text" value="" required>
						</div>
					</div>
					
					<!-- Beschreibung -->
					<div class="form-group text optional bild-beschreibung">
						<label class="col-sm-4 text optional control-label" for="edit_bild_beschreibung">Beschreibung</label>
						<div class="col-sm-8 controls">
							<textarea class="form-control text required" id="edit_bild_beschreibung" name="b_beschreibung" required></textarea>
						</div>
					</div>
					
					<input class="btn btn-primary pull-right" type="submit" value="Speichern" />
					<div class="clearfix" />
				</form>
			</div>
		</div>
	</div>
	
	<!-- Bearbeiten der Daten -->
	<form id="data_edit" class="form-horizontal" role="form">
		<!-- Hidden Values -->
		<input type="hidden" name="c" value="Product" />
		<input type="hidden" name="a" value="SaveProduct" />
		<input type="hidden" name="p_id" value="<?= $this->Produkt->ID; ?>" />
		
		<!-- Kategorie -->
		<div class="form-group string required produkt-kategorie">
			<label class="col-sm-4 string required control-label" for="edit_produkt_kategorie">Kategorie</label>
			<div class="col-sm-6 controls">
				<?php
					echo HTML::DropDownFor($this->Kategorien, $this->Produkt->KategorieID, "ID", "Name", "- keine Kategorie -",
										array(
											"id" => "edit_produkt_kategorie"
											, "class" => "form-control requirede produkt-kategorie"
											, "name" => "p_kategorie"
										), true);
				?>
			</div>
		</div>
		
		<!-- Name -->
		<div class="form-group string required produkt-name">
			<label class="col-sm-4 string required control-label" for="edit_produkt_name">Name</label>
			<div class="col-sm-6 controls">
				<input class="form-control string required" id="edit_produkt_name" name="p_name" type="text" value="<?= HTML::Write($this->Produkt->Name); ?>" required>
			</div>
		</div>
		
		<!-- Beschreibung -->
		<div class="form-group text optional produkt-beschreibung">
			<label class="col-sm-4 text optional control-label" for="edit_produkt_beschreibung">Beschreibung</label>
			<div class="col-sm-8 controls">
				<textarea class="form-control text required" id="edit_produkt_beschreibung" name="p_beschreibung" required><?= HTML::Write($this->Produkt->Beschreibung); ?></textarea>
			</div>
		</div>
		
		<!-- Preis -->
		<div class="form-group string required produkt-preis">
			<label class="col-sm-4 string required control-label" for="edit_produkt_preis">Preis</label>
			<div class="col-sm-4 controls">
				<input class="form-control string required" id="edit_produkt_preis" name="p_preis" type="number" step="any" value="<?= HTML::Write($this->Produkt->Preis); ?>" required>
			</div>
		</div>
		
		<!-- Speichern/Abbrechen -->
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button id="submit-edit" class="btn btn-primary" type="button" onclick="submitAjax('data_edit', onSaveComplete);">Speichern</button>
				<button id="cancel-edit" type="reset" class="btn btn-danger" onclick="toggleView()">Abbrechen</button>
			</div>
		</div>
	</form>
</div>

<script>
	$(document).ready(function () {
	$("#add_picture").hide();
<?php
	if (!empty($this->Produkt->ID) && $this->Produkt->ID > 0)
	{
?>
		$("#data_edit").hide();
<?php
	}
	else
	{
?>
		$("#data_view").hide();
		$("#cancel-edit").hide();
		$("#data-edit-button").hide();
<?php
	}
?>
	});
	
	function toggleAddPic() {
		$("#add_picture").toggle(200);
	}
</script>

